package com.zzyl.task;

import com.zzyl.entity.Reservation;
import com.zzyl.mapper.ReservationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class ReservationTask {
    @Autowired
    ReservationMapper reservationMapper;

    @Scheduled(cron="0 1,31 * * * ?")
    private void updateReservation(){
        //判断表中预约时间如果已经到时间了但是状态还是待报道，就将状态改为过期
        LocalDateTime now = LocalDateTime.now();
        //根据当前时间戳查询出小于当前时间的预约记录，并且状态为0的预约记录
        List<Reservation> reservations = reservationMapper.getReservationsByTime(now);
        //讲这些记录的状态都改为3（过期）
        for (Reservation reservation : reservations) {
            reservation.setStatus(3);
            reservationMapper.GQ(reservation);
        }
    }
}
